package com.vcc.boss.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vcc.core.annotations.RestPack;
import com.vcc.core.exception.ProgramException;
import com.vcc.data.entity.Wallet;
import com.vcc.service.boss.response.wellat.WalletVoBoss;
import com.vcc.service.sa.BossUserUtil;
import com.vcc.service.service.UserService;
import com.vcc.service.service.WalletDetailService;
import com.vcc.service.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("wallet")
public class WalletController {

    @Autowired
    private WalletService walletService;
    @Autowired
    private WalletDetailService walletDetailService;

    @Autowired
    private UserService userService;

    @RestPack
    @SaCheckPermission(value = ":wallet:view")
    @SaCheckLogin
    @GetMapping("refreshUsableQuota")
    public List<WalletVoBoss> refreshUsableQuota(Long targetUserId) {
        Long dealerId = userService.getDealerIdById(targetUserId);
        if (!BossUserUtil.hasAllData() && !dealerId.equals(BossUserUtil.getId())) {
            throw new ProgramException("无权处理该用户的参数配置");
        }
        List<Wallet> wallets = walletService.listByUserId(targetUserId);
        return wallets.stream().map(WalletVoBoss::new).collect(Collectors.toList());
    }

}
